<?php 
$page_title = "21 Game - Index";
include("header.php"); ?>

<div class="container">
<center><h2><b><IMG SRC="images/favicon.ico"> <span style="color: red;">Sjo-21-Game</span> <IMG SRC="images/favicon.ico"></b></h2></center>
</br>
Welcome to our <b>21-Game</b> or <b>"Black Jack"</b> application. A funny website where you can find people who likes playing Black Jack like you.
First of all, you have to register introducing your personal information. Then we give you 300 points to you, that you can bet in your games. Also you can choose an opponent and challenge them. When you're challenged with a player you can bet your points and then he may accept or reject your bet.
<h3><b><u>Instructions:</u></b></h3>
First of all you need to challenge some player, then, when the player accept the challenge the game start. You recieve two random cards, and you can try to ask for another card or stop and stay with your initial cards.
The objective it's the aproximation to 21 points with the values of the cards. The value of the Ace 1 point, the value of the figures (Jack, Queen and King) have a value of 10 points and the others cards have the value of his number in every chase.
If you exceed of 21 points you lose your bet and your opponent win the game.
</div>



<?php
// Page header:
echo '<div class="container"><h3><b><u>Scores:</u></b></h3></div>';

require ('sql/connection.php'); // Connect to the db.
		
// Make the query:
$q = "SELECT player_id, nickname, coins FROM Players order by coins desc limit 0,5";		
$r = @mysqli_query ($dbc, $q); // Run the query.

$o = "SELECT player_id FROM Players";
$p = @mysqli_query ($dbc, $o);
// Count the number of returned rows:
$num = mysqli_num_rows($p);

if ($num > 0) { // If it ran OK, display the records.

	// Print how many users there are in our database:
	echo "<div class='container'><b>$num registered players</b></div></br>";

	// Table header.
	echo '<div class="container"><table align="center" cellspacing="3" cellpadding="3" width="75%" border="3">
	<tr><td align="left"><b>ID</b></td>
	<td align="left"><b>Nickname</b></td>
	<td align="left"><b>Coins</b></td>';
	
	// Fetch and print all the records:
	while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
		echo 
		'<tr><td align="left">' . $row['player_id'] .
		'</td><td align="left">' . $row['nickname'] .
		'</td><td align="left">' . $row['coins'] .
		'</tr></div>';
		
	}

	echo '</table></br>'; // Close the table.
	
	
	mysqli_free_result ($r); // Free up the resources.	

} else { // If no records were returned.

	echo '<p class="error">This table is empty</p>';

}

mysqli_close($dbc); // Close the database connection.
?>



<?php include("footer.php"); ?>